package com.xx.xx;

import java.util.Map;
import java.util.UUID;

public class Formulas1 extends Formulas{

	public String runs(Map<String,Object> map,String[] fieldHandle,String type){
		if(type.equals("0")){
			return super.runs(map, fieldHandle);
		}
		int fieldHandleLen = fieldHandle.length;
		String gss[][] = new String[fieldHandleLen][fieldHandleLen];
		int w1 = 0;
		int w2 = 0;
		boolean iscstart = false;
		for(int i=0;i<fieldHandleLen;i++){
			if(fieldHandle[i].equals("(")){
				iscstart = true;
				w1 ++;
				continue;
			}
			if(fieldHandle[i].equals(")")){
				iscstart = false;
				w2 = 0;
				w1 ++;
				continue;
			}
			if(iscstart){
				gss[w1][w2] = fieldHandle[i];
				w2 ++;
			}else{
				gss[w1][w2] = fieldHandle[i];
				w1++;
			}
		}
		String allNewStr = "";
		for(int i=0;i<fieldHandleLen;i++){
			String[] cstr = gss[i];
			String ss = "";
			int j = 0;
			for(String s : cstr){
				if(s == null){
					break;
				}
				ss += j == 0 ? s : ","+s;
				j ++;
			}
			String newStr[] = ss.split(",");
			if(newStr.length>1){
				String data = super.runs(map, newStr);
				String uuid = UUID.randomUUID().toString().replace("-", "");
				map.put(uuid, data);
				allNewStr += i == 0 ? uuid : ","+uuid;
			}
			if(j == 1){
				allNewStr += i == 0 ? cstr[0] : ","+cstr[0];
			}
		}
		String allNewArray[] = allNewStr.split(",");
		String data = super.runs(map, allNewArray);
		return data;
	}
	
}
